feat: add interpreter generator#225
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results 1 files 1 suites 1m 40s ⏱️ Results for commit da62359. ♻️ This comment has been updated with latest results. |
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
There was a problem hiding this comment.
Pull request overview
Adds a first-class, source-generated Interpreter path to PatternKit (generator + diagnostics), updates the examples/tests/DI wiring to exercise the generated interpreters alongside the fluent runtime, and documents the generated workflow in the pattern docs and generator docs.
Changes:
- Introduces
InterpreterGenerator(incremental source generator) with diagnostics PKINT001–PKINT004 and corresponding generator tests. - Adds generated pricing/eligibility interpreter hosts to the
InterpreterDemoexample, validates parity with fluent interpreters in TinyBDD tests, and exposes them viaIServiceCollectionexample registrations. - Updates documentation and the production-readiness catalog to include the generator path and new docs entry.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Generators.Tests/InterpreterGeneratorTests.cs | Adds generator-level tests for interpreter source emission and diagnostics. |
| test/PatternKit.Examples.Tests/InterpreterDemo/InterpreterDemoTests.cs | Adds parity tests comparing fluent vs generated interpreters. |
| test/PatternKit.Examples.Tests/DependencyInjection/PatternKitExampleDependencyInjectionTests.cs | Extends DI integration test to resolve and exercise generated interpreter example services. |
| src/PatternKit.Generators/Interpreter/InterpreterGenerator.cs | New incremental generator that emits interpreter factory methods and diagnostics. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new PKINT*** diagnostics in analyzer release tracking. |
| src/PatternKit.Generators.Abstractions/Interpreter/InterpreterAttributes.cs | Adds generator-facing attributes for declaring interpreter hosts and rules. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Updates the catalog entry to include the generator docs/source/tests for Interpreter. |
| src/PatternKit.Examples/InterpreterDemo/InterpreterDemo.cs | Adds generated rule hosts and exposes CreateGenerated*Interpreter() helpers. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Registers generated interpreter examples in AddPatternKitExamples(). |
| docs/patterns/behavioral/interpreter/real-world-examples.md | Documents a source-generated variant in the real-world interpreter example. |
| docs/patterns/behavioral/interpreter/index.md | Adds a “Generated Path” section and links to generator docs. |
| docs/guides/pattern-coverage.md | Updates interpreter coverage status to “Interpreter generator”. |
| docs/generators/toc.yml | Adds Interpreter generator docs to the generators TOC. |
| docs/generators/interpreter.md | New generator documentation page (usage, signatures, diagnostics, DI). |
| docs/generators/index.md | Adds Interpreter generator to the generator overview table and examples list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var rules = GetRules(type, contextType, resultType, context); | ||
| if (rules.Length == 0) | ||
| { | ||
| context.ReportDiagnostic(Diagnostic.Create(MissingRules, node.Identifier.GetLocation(), type.Name)); | ||
| return; | ||
| } |
| var ns = type.ContainingNamespace.IsGlobalNamespace ? null : type.ContainingNamespace.ToDisplayString(); | ||
| if (ns is not null) | ||
| { | ||
| sb.Append("namespace ").Append(ns).AppendLine(";"); | ||
| sb.AppendLine(); | ||
| } | ||
|
|
||
| sb.Append("partial ").Append(type.TypeKind == TypeKind.Struct ? "struct" : "class").Append(' ').Append(type.Name).AppendLine(); | ||
| sb.AppendLine("{"); | ||
| sb.Append(" public static global::PatternKit.Behavioral.Interpreter.Interpreter<") |
|
|
||
| // Interpreter - generated DSL rule factory | ||
| [GenerateInterpreter(typeof(PricingContext), typeof(decimal))] | ||
| public static partial class PricingRules { } |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #225 +/- ##
==========================================
+ Coverage 91.49% 96.50% +5.00%
==========================================
Files 270 272 +2
Lines 25798 26029 +231
Branches 3569 3612 +43
==========================================
+ Hits 23605 25118 +1513
+ Misses 965 911 -54
+ Partials 1228 0 -1228
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code Coverage |
| sb.AppendLine(); | ||
| } | ||
|
|
||
| sb.Append("partial ").Append(type.TypeKind == TypeKind.Struct ? "struct" : "class").Append(' ').Append(type.Name).AppendLine(); |
| MetadataReference.CreateFromFile(GetAbstractionsAssemblyPath()), | ||
| MetadataReference.CreateFromFile(typeof(PatternKit.Behavioral.Interpreter.Interpreter<,>).Assembly.Location) | ||
| ]); | ||
|
|
||
| private static string GetAbstractionsAssemblyPath() | ||
| => Path.Combine( | ||
| Path.GetDirectoryName(typeof(InterpreterGenerator).Assembly.Location)!, | ||
| "PatternKit.Generators.Abstractions.dll"); | ||
|
|
Closes #206.\n\nAdds a source-generated Interpreter path with compile-time diagnostics, TinyBDD generator coverage, generated e-commerce pricing and eligibility examples, IServiceCollection registration, production-readiness catalog updates, and generator/user documentation.